#ifndef __BTL_FINGERPRINT_TIMER_H__
#define __BTL_FINGERPRINT_TIMER_H__
#include "btl_config.h"
#include "fp_log.h"

void fp_timer_init(void);
// void fp_timer_stop(void);
void fp_timer_delay_us(uint32_t count);
void fp_timer_delay_ms(uint32_t count);

void delayms(void (*callback)(void), uint32_t timeout);

unsigned int fp_timer_get(void);
unsigned int fp_timer_diff_of(unsigned int begin);

void fp_timer_handle(int n);
// void fp_timer_msleep(unsigned int msleep);
// unsigned int fp_timer_test(void);

#define TIME_MEASURE_INIT(id)   unsigned int time##id = fp_timer_get()
#define TIME_MEASURE_UPDATE(id) time##id = fp_timer_get()
#define TIME_MEASURE_DIFFNOW(id, tag)            \
    ({                                           \
        unsigned int diff = 0;                   \
        do {                                     \
            diff = fp_timer_diff_of(time##id);   \
            bf_print_d("%s spend %lu ms", tag, diff); \
        } while (0);                             \
        diff;                                    \
    })

#define TIME_MEASURE_DIFF_PRINT(id, tag)                \
    do {                                                \
        unsigned int diff = fp_timer_diff_of(time##id); \
        bf_print_d("%s spend %lu ms", tag, diff);            \
    } while (0)

#define TIME_MEASURE_DIFFOF(id) fp_timer_diff_of(time##id)


void delay_count(int count);

#define TIMEROUT 10
void timer_handle(void* p);

// void START_TIME(void);
// uint32_t GET_TIME(void);

#endif /* __BTL_FINGERPRINT_TIMER_H__ */
